<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Louzhangfangan;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class LouzhangfanganController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Louzhangfangan(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('signdate');
            $grid->column('fanganfiles');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Louzhangfangan(), function (Show $show) {
            $show->field('title');
            $show->field('signdate');
            $show->content('内容')->unescape();
            $show->fanganfiles()->file();
            $show->panel()
                ->tools(function ($tools) {
                    $tools->disableList();
                    $tools->disableDelete();
                });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Louzhangfangan(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->date('signdate');
            $form->editor('content');
            $form->multipleFile('fanganfiles')->autoUpload()->limit(3)->saving(function ($files) {
                return json_encode($files);
            });
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
